﻿@model IEnumerable<vnMcdonald.Models.Order>

@{
    ViewBag.Title = "DANH SÁCH ĐƠN ĐẶT HÀNG";
    Layout = "~/Views/Shared/_LayoutAdmin.cshtml";
}

<h2>DANH SÁCH ĐƠN ĐẶT HÀNG</h2>
<div id="ordermenu">
    <ul id="ul-ordermenu">
        <li rel="0" class="order-m-active">Chưa xử lý</li>
        <li rel="1">Đã xử lý</li>
        <li rel="2">Đã giao hàng</li>
    </ul>
</div>
<table class="thetable">
    <tr>
        <th scope="col" width="5%">STT</th>
        <th scope="col" width="15%">MÃ ĐH</th>
        <th scope="col" width="20%">Tổng Giá(VNĐ)</th>
        <th scope="col" width="20%">Ngày tạo</th>
        <th scope="col" width="30%">Khách hàng</th>
        <th scope="col" width="10%">Tùy chọn</th>
    </tr>
    <tbody id="reloadorder">
        @{
            int i = 0;
            foreach (var item in Model)
            {
                i=i+1;
                <tr>
                    <td class="text-center">@i</td>
                    <td class="text-center">@Html.DisplayFor(modelItem => item.Codes)</td>
                    <td class="text-center">@Html.DisplayFor(modelItem => item.TotalPrice)</td>
                    <td class="text-center">@Html.DisplayFor(modelItem => item.CreateDate).ToString().Substring(0, 10)</td>
                    <td class="text-center">@Html.DisplayFor(modelItem => item.Recipient)</td>
                    <td class="text-center">
                        <a href="@Url.Action("OrderView","admin",new { id=item.OrderId })" title="Xem" class="view"><span>Xem</span></a>
                    </td>
                </tr>
            }
        }
    </tbody>
</table>
<script>
    $(document).ready(function () {
        var check = 0;
        var refresh1 = function () {
            $.ajax({
                type: "post",
                url: "/admin/autoreloadOrder",
                success: function (data) {
                    if (check == 0) {
                        $("#reloadorder").empty().append(data);
                    }
                    setTimeout(refresh1, 1500);
                }
            });
        }
        $(function () {
            refresh1();
        });

        $("#ul-ordermenu li").click(function () {
            var stt = $(this).attr('rel');
            check = stt;
            var elements = document.getElementsByClassName('order-m-active');
            if (elements.length > 0) {
                $("#ul-ordermenu li").removeClass('order-m-active');
                $(this).addClass("order-m-active");
            }
            $.ajax({
                type: 'post',
                url: '/admin/autoreloadOrder',
                data: { stt: stt },
                success: function (data) {
                    $("#reloadorder").empty().append(data);
                }
            });
        });
    });
</script>